<el-dialog id="formShare" title="分享" :visible.sync="dialogShareVisible" width="600px" v-cloak >
    <#--<el-scrollbar class="ms-scrollbar" style="height: 100%;">-->
        <el-form ref="shareForm" :model="shareForm" :rules="shareRules" size="mini" label-width="100px" >
            <el-form-item  label="选择用户:" prop="userIds">
                <el-select v-model="shareForm.userIds"
                           :style="{width: '100%'}"
                           filterable
                           multiple
                           :disabled="false"
                           placeholder="请选择">
                    <el-option v-for='item in userOptions' :key="item.id" :value="item.id"
                               :label="item.account"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="有效期:" prop="expiredDate">
                <el-date-picker
                        v-model="shareForm.expiredDate"
                        placeholder="请选择有效期"
                        :readonly="false"
                        :disabled="false"
                        :clearable="true"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        :style="{width:'100%'}"
                        type="date">
                </el-date-picker>
            </el-form-item>
            <#--<el-form-item  label="加密分享:" prop="password">-->
                <#--<el-input-->
                        <#--:disabled="false"-->
                        <#--:readonly="false"-->
                        <#--v-model="shareForm.password"-->
                        <#--:style="{width: '100%'}"-->
                        <#--placeholder="请输入密码">-->
                <#--</el-input>-->
            <#--</el-form-item>-->
            <el-form-item  label="是否通知:" prop="announced">
                <el-radio-group v-model="shareForm.announced">
                    <el-radio :label="true">通知</el-radio>
                    <el-radio :label="false">不通知</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item  label="通知方式:" prop="announcementType" v-if="shareForm.announced">
                <el-checkbox-group v-model="shareForm.announcementType" @change="handleCheckedNotice">
                    <el-checkbox label="SYS">系统通知</el-checkbox>
                    <el-checkbox label="SMS">短信</el-checkbox>
                    <el-checkbox label="EMAIL">邮箱</el-checkbox>
                </el-checkbox-group>
                <span style="color:red" >* </span><span>{{noticeSelectTips}}</span>
            </el-form-item>
        </el-form>
    <#--</el-scrollbar>-->
    <div slot="footer">
        <el-button size="mini" @click="dialogShareVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="shareConfirm()">确 认</el-button>
    </div>
</el-dialog>
<script>
    var formShare = new Vue({
        el: '#formShare',
        data: function () {
            return {
                shareForm: {
                    id:'',
                    userIds:[],
                    announcementType:[]
                },
                shareRules: {
                    // 申请说明
                    userIds: [ { "required": true, "message": "分享的用户不能为空",  trigger: 'blur'}],
                    expiredDate: [ { "required": true, "message": "请选择有效期",  trigger: 'blur'}],
                    // password:[{"pattern": /^[0-9A-Za-z]{8,16}$/, "message": "密码长度为8-16个字符，不能使用中文、空格，不能含有非法字符"} ],///^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/
                },
                dialogShareVisible:false,
                userOptions:[],
                noticeSelectTips:"若用户未绑定手机号或邮箱，默认发送系统通知。",
            };
        },
        watch: {
        },
        computed: {},
        methods: {
            showShareDialog: function(row){
                this.getUserData();
                this.shareForm={ fileId:'', userIds:[],announcementType:[]};
                this.dialogShareVisible=true;
                this.$nextTick(function () {
                    this.$refs.shareForm.clearValidate();
                });
                this.shareForm.fileId=row[0].id;
            },

            shareConfirm:function(){
                var that = this;
                that.$refs.shareForm.validate(function (valid) {
                    if (valid) {
                        ms.http.post(ms.manager + "/cms/document/share.do", that.shareForm,{
                            headers: {
                                'Content-Type': 'application/json'
                            }
                        }).then(function (res) {
                            if(res.code===200){
                                that.$notify({
                                    type: 'success',
                                    message: "分享成功"
                                });
                                //分享成功，刷新列表
                                that.dialogShareVisible = false;
                                indexVue.list();
                            }else{
                                that.$notify({
                                    type: 'error',
                                    message: "分享失败"
                                });
                            }


                        }).catch(function (err) {
                            that.$notify({
                                type: 'error',
                                message: "分享失败"
                            });
                        });
                    }
                })
            },
            //获取用户列表
            getUserData:function () {
                var that = this;
                var page = {
                    pageNo: 1,
                    pageSize: "99999"//that.pageSizeDialog
                };
                ms.http.post(ms.manager + "/basic/manager/list.do", Object.assign({}, page),{
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then(function (res) {
                    if(res.code == 200){
                        that.userOptions = res.data.records;
                    }
                });
            },
            handleCheckedNotice: function (value) {


            },
        },
        created: function () {}
    });
</script>
<style>

</style>
